<?php
/**
 * Copyright 2014 TinPHP Systems, Inc.
 * @package TinPhp
 */
/** 各种状态枚举类 */
class StatusCode
{
  const OK                  = 0;
  const EXCEPTION           = 1;
  const INVALID_INPUT       = 2;
  const INVALID_FILE_TYPE   = 3;
  const INVALID_FILE_SIZE   = 4;
  
  // web services
  // 100+
  const WEBSERVICE_FAILED   = 100; 
  
  // auth
  // 200+
  const SESSION_EXPIRED     = 200;
  const TICKET_EXPIRED      = 201;
  const BAD_TICKET          = 202;
  const KICKED_OFF          = 203;

  // seg
  // 300+
  const SEG_RET_ERROR       = 301;
}
/** TinStatus各种状态枚举类 */
class TinStatus
{
  private $code;
  private $message;

  public function TinStatus($sc, $msg="")
  {
    $this->code = $sc;
    $this->message = $msg;
  }

  public function isok()
  {
    return StatusCode::OK === $this->code;
  }

  public function isexception()
  {
    return StatusCode::EXCEPTION === $this->code;
  }

  public function isInvalidInput()
  {
    return StatusCode::INVALID_INPUT === $this->code;
  }

  public function isInvalidFileType()
  {
    return StatusCode::INVALID_FILE_TYPE === $this->code;
  }

  public function isWebServiceFailed()
  {
    return StatusCode::WEBSERVICE_FAILED === $this->code;
  }

  public function isSessExpired()
  {
    return StatusCode::SESSION_EXPIRED === $this->code;
  }

  public function isKickedOff()
  {
    return StatusCode::KICKED_OFF === $this->code;
  }

  public function isSegRetError()
  {
    return StatusCode::SEG_RET_ERROR === $this->code;
  }

  public function iscode($scode)
  {
    return $scode === $this->code;
  }

  public function code()
  {
    return $this->code;
  }

  public function message()
  {
    return $this->message;
  }

  public function toString()
  {
    return '[code: ' . $this->code . ', message: ' . $this->message . ']';
  }

  public static function OK($msg='')
  {
    return new TinStatus(StatusCode::OK, $msg);
  }

  public static function EXCEPTION($msg='')
  {
    return new TinStatus(StatusCode::EXCEPTION, $msg);
  }
  
  public static function INVALID_INPUT($msg='')
  {
    return new TinStatus(StatusCode::INVALID_INPUT, $msg);
  } 

  public static function WEBSERVICE_FAILED($msg='')
  {
    return new TinStatus(StatusCode::EXCEPTION, $msg);
  }

  public static function SESSION_EXPIRED($msg='')
  {
    return new TinStatus(StatusCode::SESSION_EXPIRED, $msg);
  }

  public static function TICKET_EXPIRED($msg='')
  {
    return new TinStatus(StatusCode::TICKET_EXPIRED, $msg);
  }

  public static function BAD_TICKET($msg='')
  {
    return new TinStatus(StatusCode::BAD_TICKET, $msg);
  }

  public static function KICKED_OFF($msg='')
  {
    return new TinStatus(StatusCode::KICKED_OFF, $msg);
  }

  public static function SEG_RET_ERROR($msg='')
  {
    return new TinStatus(StatusCode::SEG_RET_ERROR, $msg);
  }
}

?>
